home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Thread Manager / Thread Manager 2.1.1d1+ / ThreadedSort / Sprocket / Lib / DragUtils.cp < prev    next >
Encoding:
Text File  |  1995-04-28  |  1.8 KB  |  73 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DragUtils.cp
  3.  
  4.     Contains:    Useful utility functions when using the Drag Manager.
  5.  
  6.     Written by: Dave Falkenburg and Cameron Esfahani
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.          <2>    11/12/94    DRF        Added #include to pick up function prototype.
  13.          <1>      9/9/94    DRF        first checked in
  14.  */
  15.  
  16. #include "Sprocket.h"
  17.  
  18. #include <Folders.h>
  19.  
  20. Boolean
  21. DragDestinationIsTheTrash(DragReference theDrag)
  22.     {
  23.     AEDesc    dropLocation;
  24.     AEDesc    dropFSSpecDesc;
  25.     Boolean    wasItDraggedToTrash = false;
  26.     OSErr    err;
  27.  
  28.     err = GetDropLocation(theDrag, &dropLocation);
  29.     if (err != noErr)
  30.         return false;
  31.  
  32.     if ((dropLocation.descriptorType != typeNull) && 
  33.         (AECoerceDesc(&dropLocation, typeFSS, &dropFSSpecDesc) == noErr))
  34.         {
  35.         FSSpec *        theDropFSSpec;
  36.         CInfoPBRec        theCatInfoPB;
  37.         long            trashDirID;
  38.         short            trashVRefNum;
  39.  
  40.         //    If we got here, the drag went to a file system thing
  41.         
  42.         HLock(dropFSSpecDesc.dataHandle);
  43.         theDropFSSpec = (FSSpec *) *dropFSSpecDesc.dataHandle;
  44.             
  45.         theCatInfoPB.dirInfo.ioCompletion = nil;
  46.         theCatInfoPB.dirInfo.ioNamePtr = (StringPtr) &theDropFSSpec->name;
  47.         theCatInfoPB.dirInfo.ioVRefNum = theDropFSSpec->vRefNum;
  48.         theCatInfoPB.dirInfo.ioFDirIndex = 0;
  49.         theCatInfoPB.dirInfo.ioDrDirID = theDropFSSpec->parID;
  50.         if (PBGetCatInfoSync(&theCatInfoPB) != noErr)
  51.             goto bail;
  52.  
  53.         //    Is it a directory?
  54.  
  55.         if (!(theCatInfoPB.dirInfo.ioFlAttrib & ioDirMask))
  56.             goto bail;
  57.         
  58.         //    Is it the trash folder?
  59.         
  60.         (void) FindFolder(kOnSystemDisk,kTrashFolderType,kCreateFolder,&trashVRefNum,&trashDirID);
  61.  
  62.         if ((theDropFSSpec->vRefNum == trashVRefNum) && (theCatInfoPB.dirInfo.ioDrDirID == trashDirID))
  63.             wasItDraggedToTrash = true;
  64.         }
  65.  
  66. bail:
  67.     HUnlock(dropFSSpecDesc.dataHandle);
  68.     AEDisposeDesc(&dropFSSpecDesc);
  69.     AEDisposeDesc(&dropLocation);
  70.  
  71.     return wasItDraggedToTrash;
  72.     }
  73.